package com.ss.android.article.base.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import com.ss.android.common.dd;

import java.util.ArrayList;
import java.util.List;

public class PriorityLinearLayout extends ViewGroup {
    public static final class PriorityLinearLayout$a extends ViewGroup.MarginLayoutParams {
        public int a;
        public int b;
        public boolean c;
        public boolean d;
        private int e;

        public PriorityLinearLayout$a(int arg2, int arg3) {
            super(arg2, arg3);
            this.c = false;
        }

        public PriorityLinearLayout$a(Context arg4, AttributeSet arg5) {
            super(arg4, arg5);
            this.c = false;
            TypedArray v0 = arg4.obtainStyledAttributes(arg5, dd.k);
            this.a = v0.getInt(dd.o, 0);
            this.b = v0.getInt(dd.n, 0);
            this.c = v0.getBoolean(dd.m, false);
            this.d = v0.getBoolean(dd.l, false);
            v0.recycle();
        }

        public PriorityLinearLayout$a(ViewGroup.LayoutParams arg2) {
            super(arg2);
            this.c = false;
        }

        static int a(PriorityLinearLayout$a arg1) {
            return arg1.e;
        }

        static int a(PriorityLinearLayout$a arg0, int arg1) {
            arg0.e = arg1;
            return arg1;
        }
    }

    private ArrayList a;
    private ArrayList b;

    public PriorityLinearLayout(Context arg2) {
        super(arg2);
        this.a = new ArrayList();
        this.b = new ArrayList();
    }

    public PriorityLinearLayout(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.a = new ArrayList();
        this.b = new ArrayList();
    }

    public PriorityLinearLayout(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.a = new ArrayList();
        this.b = new ArrayList();
    }

    private static int a(View arg5, List<View> arg6, int arg7) {
        int v4;
        int v0_1;
        int v3;
        while (true) {
            if (arg6.size() != 0) {
                ViewGroup.LayoutParams v0 = arg5.getLayoutParams();
                v3 = arg6.size() - 1;
                if (PriorityLinearLayout.a((PriorityLinearLayout$a) v0, (PriorityLinearLayout$a) arg6.get(0).getLayoutParams(), arg7) <= 0) {
                    v0_1 = 0;
                } else if (PriorityLinearLayout.a(((PriorityLinearLayout$a) v0), (PriorityLinearLayout$a) arg6.get(v3).getLayoutParams(), arg7) >= 0) {
                    v0_1 = v3 + 1;
                } else if (1 == v3) {
                    v0_1 = v3;
                } else {
                    v4 = v3 / 2;
                    v0_1 = PriorityLinearLayout.a(((PriorityLinearLayout$a) v0), (PriorityLinearLayout$a) arg6.get(v4).getLayoutParams(), arg7);
                    if (v0_1 == 0) {
                        v0_1 = v4;
                    } else if (v0_1 < 0) {
                        arg6 = arg6.subList(0, v4);
                        continue;
                    } else {
                        break;
                    }
                }
            } else {
                return 0;
            }

            return v0_1;
        }

        return PriorityLinearLayout.a(arg5, arg6.subList(v4, v3 + 1), arg7) + v4;
    }

    private static int a(PriorityLinearLayout$a arg2, PriorityLinearLayout$a arg3, int arg4) {
        int v0 = arg4 == 0 ? arg2.a - arg3.a : arg2.b - arg3.b;
        return v0;
    }

    public final void a() {
        this.a.clear();
        this.b.clear();
        int v2 = this.getChildCount();
        int v0;
        for (v0 = 0; v0 < v2; ++v0) {
            View v3 = this.getChildAt(v0);
            this.a.add(PriorityLinearLayout.a(v3, this.a, 0), v3);
            this.b.add(PriorityLinearLayout.a(v3, this.b, 1), v3);
        }
    }

    protected boolean checkLayoutParams(ViewGroup.LayoutParams arg2) {
        return arg2 instanceof PriorityLinearLayout$a;
    }

    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new PriorityLinearLayout$a(-2, -2);
    }

    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet arg3) {
        return new PriorityLinearLayout$a(this.getContext(), arg3);
    }

    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams arg2) {
        return new PriorityLinearLayout$a(arg2);
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        this.a();
    }

    protected void onLayout(boolean arg11, int arg12, int arg13, int arg14, int arg15) {
        int v0_1;
        int v5 = arg15 - arg13;
        int v2 = this.getPaddingLeft();
        int v6 = this.b.size();
        int v3 = 0;
        while (v3 < v6) {
            Object v1 = this.b.get(v3);
            ViewGroup.LayoutParams v0 = ((View) v1).getLayoutParams();
            if (((View) v1).getVisibility() == View.GONE) {
                v0_1 = v2;
            } else if ((PriorityLinearLayout$a.a(((PriorityLinearLayout$a) v0)) & 1) == 0) {
                ((View) v1).layout(0, 0, 0, 0);
                v0_1 = v2;
            } else {
                int v7 = ((PriorityLinearLayout$a) v0).leftMargin + v2;
                if (((PriorityLinearLayout$a) v0).c) {
                    v2 = ((PriorityLinearLayout$a) v0).topMargin + this.getPaddingTop();
                } else if (((PriorityLinearLayout$a) v0).d) {
                    v2 = v5 - this.getPaddingBottom() - ((PriorityLinearLayout$a) v0).bottomMargin - ((View) v1).getMeasuredHeight();
                } else {
                    v2 = (v5 - ((View) v1).getMeasuredHeight()) / 2;
                }
                ((View) v1).layout(v7, v2, ((View) v1).getMeasuredWidth() + v7, ((View) v1).getMeasuredHeight() + v2);
                v0_1 = ((PriorityLinearLayout$a) v0).rightMargin + (((View) v1).getMeasuredWidth() + v7);
            }

            ++v3;
            v2 = v0_1;
        }
    }

    protected void onMeasure(int arg12, int arg13) {
        int v1_1;
        int v0_1;
        Object v0;
        int v10 = View.GONE;
        int v6 = View.MeasureSpec.getSize(arg12);
        int v3 = this.getPaddingLeft() + this.getPaddingRight();
        int v5 = this.getPaddingBottom() + this.getPaddingTop();
        int v4 = this.a.size() - 1;
        int v2 = v5;
        while (v4 >= 0) {
            if (v3 >= v6) {
                break;
            }

            v0 = this.a.get(v4);
            if (((View) v0).getVisibility() != v10) {
                ViewGroup.LayoutParams v1 = ((View) v0).getLayoutParams();
                if (((PriorityLinearLayout$a) v1).leftMargin + v3 + ((PriorityLinearLayout$a) v1).rightMargin + ((PriorityLinearLayout$a) v1).width <= v6) {
                    v3 += ((PriorityLinearLayout$a) v1).leftMargin + ((PriorityLinearLayout$a) v1).rightMargin;
                    ((View) v0).measure(PriorityLinearLayout.getChildMeasureSpec(arg12, v3, ((PriorityLinearLayout$a) v1).width), PriorityLinearLayout.getChildMeasureSpec(arg13, ((PriorityLinearLayout$a) v1).topMargin + v5 + ((PriorityLinearLayout$a) v1).bottomMargin, ((PriorityLinearLayout$a) v1).height));
                    PriorityLinearLayout$a.a(((PriorityLinearLayout$a) v1), PriorityLinearLayout$a.a(((PriorityLinearLayout$a) v1)) | 1);
                    v3 += ((View) v0).getMeasuredWidth();
                    v0_1 = Math.max(((View) v0).getMeasuredHeight() + v5 + ((PriorityLinearLayout$a) v1).topMargin + ((PriorityLinearLayout$a) v1).bottomMargin, v2);
                    v1_1 = v3;
                } else {
                    break;
                }
            } else {
                v0_1 = v2;
                v1_1 = v3;
            }

            --v4;
            v2 = v0_1;
            v3 = v1_1;
        }

        for (v1_1 = v4; v1_1 >= 0; --v1_1) {
            v0 = this.a.get(v1_1);
            if (((View) v0).getVisibility() != v10) {
                ViewGroup.LayoutParams v0_2 = ((View) v0).getLayoutParams();
                PriorityLinearLayout$a.a(((PriorityLinearLayout$a) v0_2), PriorityLinearLayout$a.a(((PriorityLinearLayout$a) v0_2)) & -2);
            }
        }

        this.setMeasuredDimension(PriorityLinearLayout.resolveSize(Math.max(v3, this.getSuggestedMinimumWidth()), arg12), PriorityLinearLayout.resolveSize(Math.max(v2, this.getSuggestedMinimumHeight()), arg13));
    }

    public boolean shouldDelayChildPressedState() {
        return false;
    }
}

